<template>
  <div class="u-p-20">
    <el-card shadow="never">
      <div slot="header">
        <span>
          <b class="u-f-16">进货商统计</b>
        </span>
      </div>

      <el-form
        :inline="true"
        :model="queryForm"
        size="small"
        class="u-text-center"
      >
        <el-form-item label="供应商">
          <el-select
            v-model="queryForm.distributor_id"
            clearable
            @change="handleChange"
          >
            <el-option label="全部" value="0"></el-option>
            <el-option
              v-for="(item, index) in distributorList"
              :key="index"
              :label="item.name"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="下单时间">
          <el-date-picker
            v-model="queryForm.time_section"
            type="daterange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            format="yyyy-MM-dd"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="订单关键字">
          <el-input
            v-model="queryForm.keyword"
            placeholder="订单关键字"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="getPageData(true)"
            >查询</el-button
          >
        </el-form-item>
      </el-form>

      <el-table :data="tableData" class="u-mt-10" v-viewer>
        <el-table-column label="id" prop="id" width="60"></el-table-column>
        <el-table-column label="用户信息" width="120">
          <template slot-scope="scope">
            <div class="head-img">
              <el-image
                class="el-img"
                :src="scope.row.head_img"
                fit="cover"
                lazy
              ></el-image>
            </div>
            <div class="nick_name">{{ scope.row.nick_name }}</div>
          </template>
        </el-table-column>
        <el-table-column label="地址信息" width="260">
          <template slot-scope="scope">
            <p>{{ scope.row.take_name }}</p>
            <p>{{ scope.row.take_phone }}</p>
            <p>{{ scope.row.take_address }}</p>
          </template>
        </el-table-column>
        <el-table-column label="订单状态" width="80">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_status == 0" type="info"
              >已取消</el-tag
            >
            <el-tag v-if="scope.row.order_status == 1" type="info"
              >待付款</el-tag
            >
            <el-tag v-if="scope.row.order_status == 2" type="success"
              >已付款</el-tag
            >
            <el-tag v-if="scope.row.order_status == 3">已发货</el-tag>
            <el-tag v-if="scope.row.order_status == 4" type="warning"
              >已收货</el-tag
            >
            <el-tag v-if="scope.row.order_status == 5" type="danger"
              >已完成</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="供应商" width="110">
          <template slot-scope="scope">
            <el-tag type="info">{{
              scope.row.distributor_name == ""
                ? "无"
                : scope.row.distributor_name
            }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="商品详情">
          <template slot-scope="scope">
            <div class="goods-items">
              <div class="goods-title">
                <span>名称：</span>
                {{ scope.row.goods_title }}
              </div>
              <div>
                <span>规格：</span>
                {{ scope.row.attribute_names }}
              </div>
            </div>
            <div
              class="goods-number"
              style="font-weight: 700"
              :style="
                scope.row.goods_number > 1 ? 'color: #409EFF' : 'color: red'
              "
              v-if="buttonType != 2 && buttonType != 7"
            >
              {{ scope.row.goods_number }}(件)
            </div>
          </template>
        </el-table-column>
        <el-table-column label="订单详情">
          <template slot-scope="scope">
            <div class="order-price info">
              <div class="label">总金额：</div>
              <div class="price" style="color: #f56c6c">
                ￥{{ scope.row.order_total }}
              </div>
            </div>
            <div class="order-price text">
              <div class="label">实际成本价：</div>
              <div class="price">￥{{ scope.row.cost_price * scope.row.goods_number}}</div>
            </div>
            <div class="order-price text">
              <div class="label">总利润：</div>
              <div class="price">￥{{ (scope.row.goods_price-scope.row.cost_price)* scope.row.goods_number}}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column label="日期" prop="create_time" sortable></el-table-column>
      </el-table>
      <div class="u-mt-20 u-text-center">
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
          :current-page="currentPage"
          :page-sizes="[10, 20, 30, 40, 50]"
          :page-size="limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </el-card>
  </div>
</template>

<script>
import commonPage from "@/mixins/common-page";
export default {
  mixins: [commonPage],
  data() {
    return {
      apiName: "order",
      apiPage: "distributorPage",
      queryForm: {
        time_section: "", //下单时间区间
        distributor_id: "",
        keyword: "",
      },
      distributorList: [],
    };
  },
  methods: {
    handleChange() {
      this.getPageData(true);
    },
    getLoadList() {
      let that = this;
      this.$api["distributor"]
        .page({ page: 1, limit: 1000 })
        .then((response) => {
          if (response.code == 1) {
            that.distributorList = response.data.pageList;
          }
        });
    },
    afterGetInfo() {},
  },
  mounted() {},
  created() {
    this.getLoadList();
  },
};
</script>
<style lang="scss" scoped>
// .el-dialog__footer {
//   text-align: left;
// }
.goods-number {
  margin-left: 20px;
  margin-top: 15px;
}
.goods-title {
  overflow: hidden;
  text-overflow: ellipsis;
  -o-text-overflow: ellipsis;
  white-space: nowrap;
  width: 300px;
  display: block;
}
.logistics-number {
  margin-top: 20%;
}
.line {
  width: 100%;
  height: 1px;
  background-color: #eee;
}
.head-img {
  width: 100%;
  text-align: center;
}
.head-img .el-img {
  width: 48px;
  height: 48px;
  border-radius: 48px;
}
.nick_name {
  width: 100%;
  text-align: center;
}
.order {
  margin-top: 10px;
  border-top: 1px solid #ebeef5;
  border-bottom: 1px solid #ebeef5;

  .order-head {
    background: #f7f7f7;
    line-height: 35px;
    .order-sn {
      margin-left: 15px;
    }
  }

  .order_main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    text-overflow: ellipsis;
    align-content: center;
    white-space: normal;
    word-break: break-all;
    line-height: 23px;
  }
}
.goods_title_p {
  display: flex;
  line-height: 30px;
  .goods_title {
    overflow: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
    white-space: nowrap;
    width: 200px;
    display: block;
  }
  .goods_names {
    overflow: hidden;
    text-overflow: ellipsis;
    -o-text-overflow: ellipsis;
    white-space: nowrap;
    width: 150px;
    display: block;
  }
}
.el-button {
  margin-bottom: 10px;
  margin-right: 10px;
  margin-left: 0;
}
.text {
  color: #409eff;
  background: #ecf5ff;
}
.info {
  color: #67c23a;
  background: #f0f9eb;
}
.order-price {
  .label {
    display: inline-block;
    width: 90px;
  }
  .price {
    display: inline-block;
    width: 80px;
    color: #999;
  }
}
</style>